from order_manager.model.users import User


class UserController:
    def __init__(self):
        self.current_user = None
        self.users: list[User] = [
            User(username='admin', password='123'),
            User(username='cust', password='123')
        ]

    def login(self, name, password) -> bool:
        """
        登录
        :return:
        """
        if self.current_user:
            print('已经登录')
            return False
        for user in self.users:
            if user.username == name and user.password == password:
                self.current_user = name
                return True
            elif user.username == name and user.password != password:
                print('密码错误')
                return False
        print('用户不存在')
        return False

    def logout(self):
        """
        注销
        :return:
        """
        self.current_user = None
        return True


